package com.ys.service.eKnowAi.impl;

import com.ys.entity.eKnowAi.EKnowScene;
import com.ys.entity.eKnowAi.EKnowSceneKnowledge;
import com.ys.entity.eKnowAi.EKnowSceneModel;
import com.ys.entity.eKnowAi.EKnowScenePromptKey;
import com.ys.mapper.eKnowAi.EKnowAiDiySqlMapper;
import com.ys.mapper.eKnowAi.EKnowSceneKnowledgeMapper;
import com.ys.mapper.eKnowAi.EKnowSceneMapper;
import com.ys.mapper.eKnowAi.EKnowSceneModelMapper;
import com.ys.service.eKnowAi.EKnowSceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("EKnowSceneService")
public class EKnowSceneServiceImpl implements EKnowSceneService {

	@Autowired
	private EKnowSceneMapper eKnowSceneMapper;

	@Autowired
	private EKnowAiDiySqlMapper eknowAiDiySqlMapper;

	@Autowired
	private EKnowSceneKnowledgeMapper eKnowSceneKnowledgeMapper;

	@Autowired
	private EKnowSceneModelMapper eKnowSceneModelMapper;



	@Override
	public int add(EKnowScene eKnowScene) {
		eKnowScene.setStatus(1);
		int result = eKnowSceneMapper.insert(eKnowScene);
		return result;
	}


	@Override
	public int update(EKnowScene eKnowScene) {
		eKnowScene.setStatus(1);
		int result = eKnowSceneMapper.update(eKnowScene);
		return result;
	}



	/**
	 * 修改提示词
	 */
	@Override
	public int updateEKnowScenePromptKey(String keyValue,long keyId,long sceneId){
		EKnowScenePromptKey eKnowScenePromptKey = new EKnowScenePromptKey();
		eKnowScenePromptKey.setSceneId(sceneId);
		eKnowScenePromptKey.setKeyId(keyId);
		eKnowScenePromptKey.setKeyValue(keyValue);
		int result = eknowAiDiySqlMapper.updateEKnowScenePromptKey(eKnowScenePromptKey);
		return result;
	}

	/**
	 * 删除场景知识库关联表
	 */
	@Override
	public int delEKnowSceneKnowledge(long sceneId){
		return eknowAiDiySqlMapper.delEKnowSceneKnowledgeBySceneId(sceneId);
	}

	/**
	 * 新增场景知识库关联表
	 */
	@Override
	public int addEKnowSceneKnowledge(long sceneId,long knowledgeBaseId){
		EKnowSceneKnowledge eKnowSceneKnowledge = new EKnowSceneKnowledge();
		eKnowSceneKnowledge.setKnowledgeBaseId(knowledgeBaseId);
		eKnowSceneKnowledge.setSceneId(sceneId);
		eKnowSceneKnowledge.setStatus(1);
		int result = eKnowSceneKnowledgeMapper.insert(eKnowSceneKnowledge);
		return result;
	}

	/**
	 * 删除场景知识库关联表
	 */
	@Override
	public int delEKnowSceneModel(long sceneId){
		return eknowAiDiySqlMapper.delEKnowSSceneModelBySceneId(sceneId);
	}

	/**
	 * 新增场景模型关联表
	 */
	@Override
	public int addEKnowSceneModel(long sceneId,long modelId){
		EKnowSceneModel eKnowSceneModel = new EKnowSceneModel();
		eKnowSceneModel.setSceneId(sceneId);
		eKnowSceneModel.setModelId(modelId);
		eKnowSceneModel.setStatus(1);
		int result = eKnowSceneModelMapper.insert(eKnowSceneModel);
		return result;

	}

	/**
	 * 删除场景信息表以及关联表
	 */
	@Override
	public int del(long id){
		return eknowAiDiySqlMapper.deleteEKnowSceneAndAssociation(id);
	}
}
